package code;

import models.ListNode;

public class ReverseList {
    public ListNode Solution(ListNode head){
        if(head==null){
            return null;
        }
        else {
            ListNode re = new ListNode(0);
            ListNode p = head.next;
            while(head.next!=null){
                head.next = re.next;
                re.next = head;
                head = p;
                p = p.next;
            }
            head.next = re.next;
            re.next = head;
            return re.next;
        }
    }
}
